/**
 * 
 */
package edu.wpi.cs509.messages.client;

import edu.wpi.cs509.clientlogic.ClientLogic;
import edu.wpi.cs509.clientlogic.ClientUpstreamLogic;
import edu.wpi.cs509.representation.ActionBaseClass;
import edu.wpi.cs509.representation.ClientGame;
import edu.wpi.cs509.representation.TeamColor;

/**
 * This is the game-update message. It is  sent to all watchers of a
 * game (ie. the players and the observer) after a player has made a 
 * valid move.
 * 
 * @author sparadis
 * 
 */
public class MsgGameUpdate extends MsgAckReply {
	/**
	 * The serialization version ID.
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * @param game ClientGame indicating current board state.
	 * @param lastMove ActionMove naming the move that this message is 
	 * being sent in response to.
	 * @param nextTurn Who's turn is next?
	 */
	private ClientGame game;
	private ActionBaseClass lastMove;
	private TeamColor nextTurn;
	
	/**
	 * Constructor -- success is true, errStr is "".
	 * @param game ClientGame indicating current board state
	 * @param lastMove ActionMove naming the move that this message 
	 *                 is being sent in response to
	 * @param nextTurn Who's turn is next?
	 */	public MsgGameUpdate(ClientGame game, ActionBaseClass lastMove, 
			TeamColor nextTurn) {
		super(true, "");
		this.game = game;
		this.lastMove = lastMove;
		this.nextTurn = nextTurn;
	}
	
	/**
	 * Constructor
	 * @param game ClientGame indicating current board state
	 * @param lastMove ActionMove naming the move that this message 
	 *                 is being sent in response to
	 * @param nextTurn Who's turn is next?
	 */
	public MsgGameUpdate(ClientGame game, ActionBaseClass lastMove, 
			TeamColor nextTurn, boolean success, String errString) {
		super(success, errString);
		this.game = game;
		this.lastMove = lastMove;
		this.nextTurn = nextTurn;
	}
	
	/**
	 * 
	 */
	@Override
	public void rxExecute() {
		System.out.println("Receiving a game update from server.");
		ClientUpstreamLogic.getInstance().receivePieceMoved(
					 lastMove, msgSucceeded(), game,
					 ClientLogic.getInstance().getUserSession(), 
					 nextTurn);
	}

}
